"""
A simple test program to demonstrate the chess engine.
"""

import chess
import sys
from bot import *
player = False

ai = dave(True)

def main():
	"""Interactive mode.  Type ? for help."""
	game = chess.Game(None, None)
	board = game.board
	for line in game.show():
		print line
	while game.ok():
		if game.turn == player:
			print '%s> ' % chess.COLORS[game.turn], 
			command = raw_input()
			words = command.split(" ")
			print
			try:
				if command == '':
					pass
				elif len(words) == 1:
					move = game.move(words[0])
					print "%s moves %s" % \
						  (chess.COLORS[game.turn], move.longAlgebraic())
					if move.capture:
						print "%s takes %s" % (move.piece.name, move.capture.name)
					for line in game.show():
						print line
					game.advance()
				else:
					print "i don't understand"
				check = game.checked()
				if check is not None:
					print "%s in check" % chess.COLORS[check]
			except chess.Error, e:
				print str(e)
		else:
			ai.move(game)
			print game.turn
			print player
			for line in game.show():
				print line
	checkmate = game.checkmated()
	print "%s checkmated" % chess.COLORS[checkmate]
		

if __name__ == '__main__':
	main()
